﻿using Server.Constant;
using Server.Enum;
using Server.Framework.Message;
using Server.Framework.Processor;
using Server.Framework.Service;
using Server.Framework.Socket;
using Server.Message.Request;
using Server.Message.Response;
using System;

namespace Server.Processor
{
    /// <summary>
    /// Author: Leil
    /// Description: 删除角色操作
    /// CreateTime: 2020/5/13 10:12:49
    /// </summary>
    [ProcessorAttr(MessageId.DELETE_MENU)]
    class DeleteMenuProcessor : IProcessor
    {

        public void Process(ProtobufAppSession session, RequestBaseMessage message)
        {
            if (message is DeleteMenuReq msg)
            {
                string sql = $"UPDATE SYS_MENU SET DEL_FLAG = 0 WHERE ID = {msg.ID}";

                DBService.Instance().ExecuteNonQuery(sql, res => {
                    OperationResp resp = new OperationResp(MessageId.OPT_RESP);
                    if (res > 0)
                    {
                        resp.Code = 200;
                        resp.OptType = (int)OptType.DELETE_MENU;
                        resp.Content = "删除成功";
                        session.Send(resp);
                    }
                    else
                    {
                        resp.Code = 500;
                        resp.OptType = (int)OptType.DELETE_MENU;
                        resp.Content = "删除失败";
                        session.Send(resp);
                    }
                });
            }
        }

    }
}
